package day05;
import java.util.Arrays;
//数组演示
public class ArrayDemo {
    public static void main(String[] args) {
        //数组的声明
        //1. 数组的定义
        //声明整型数组a,包含5个元素，每一个元素都是int类型，默认为0
        /*int[] a=new int[5];
        System.out.println(a);
        double[] b=new double[10];
        System.out.println(b);
        boolean[] c=new boolean[26];
        System.out.println(c);
        int[] d=new int[2];
        ///d[0]=1;
        //d=int[]{1,2,3};
        int[] f={1,2,3};
        int[] g;
        g=new int[]{1,2,3};
        int arr1[]=new int[]{2,5,8};
        //String[] rrrs=new String['2','2','2'];
        int arr2[]=new int[5];
        arr2[0]=1;
        System.out.println(arr2[0]);
        arr2[4]=99;
        System.out.println(arr2[4]);
        System.out.println("数组的长度:"+arr2.length);
        //数组的访问
        int array[]=new int[]{1,2,3,4,5,6,7,8,9,10};
        System.out.println(array.length);
        System.out.println(array[array.length-1]);
        //System.out.println(array[-1]);
        System.out.println(array[1]);
        System.out.println(array[0]);

        String[] arrs=new String[7];
        arrs[0]="hello";
        arrs[1]="I";
        arrs[2]="LOVE";
        arrs[3]="YOU";
        System.out.println(arrs[1]+" "+arrs[2]+" "+arrs[3]);*/

        //数组的遍历：
        /*int[] arr=new int[10];
        //给数组赋值
        for (int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*100);
            System.out.println(arr[i]);
        }*/

        //数组的复制
        int [] a=new int[]{1,2,3,4,5};
        int [] b=new int[8];
        //a : 原数组
        //0: 原数组的起始位置
        //b: 目标数组
        //0: 目标数组的起始位置
        //3: 复制的长度
        System.arraycopy(a,0,b,5,3);
        for (int i=0;i<b.length;i++){
            System.out.print(b[i]+"\t");
        }
        System.out.println();
        int [] c=Arrays.copyOf(a,6);
        //a: 原数组
        //c: 目标数组
        //6: 复制的长度
        for (int i=0;i<c.length;i++){
            System.out.print(c[i]+"\t");
        }
    }
}
